﻿namespace _模拟把集合随机打乱
{
    public class Program
    {
        public static void Main()
        {
            // 创建一个整数列表
            List<int> numbers = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

            // 打乱列表的顺序
            numbers.Shuffle();

            // 输出打乱后的列表
            foreach (int num in numbers)
            {
                Console.WriteLine(num);
            }
        }
    }

    public static class ListExtensions
    {
        private static readonly Random rng = new Random();

        public static void Shuffle<T>(this IList<T> list)
        {
            int n = list.Count;
            while (n > 1)
            {
                n--;
                int k = rng.Next(n + 1);
                T value = list[k];
                list[k] = list[n];
                list[n] = value;
            }
        }
    }
}
